package be.ac.ua.ecampus.cmat;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.HashSet;

import be.ac.ua.ecampus.cmat.types.Entity;
import be.ac.ua.ecampus.cmat.types.Program;
import be.ac.ua.ecampus.cmat.types.Syllabus;

public class QueryHandler {
	Connection fConnection;
	
	public QueryHandler(Connection connection) {
		fConnection = connection;
	}
	
	public QueryHandler() {
		fConnection = DBConnection.connect();
	}
	
	public Collection<Entity> search(String search) throws SQLException {
		Collection<Entity> c = new HashSet<Entity>();
		c.add(new Program(1, "descr"));
		c.add(new Syllabus(1, 2.3, "de", "ac20043", true));
		return c;
	}
	
	public Program getProgram(int id) throws SQLException {
		/*
		Program program = null;
		final String query = "SELECT description FROM student2011.CMAT_PROGRAM WHERE id='" + id + "' LIMIT 1";
		final Statement statement = this.fConnection.createStatement();
		final ResultSet resultSet = statement.executeQuery(query);
		while (resultSet.next()) {
			program = new Program(id, resultSet.getString("description"));

		}
		statement.close();
		return program;
		*/
		return new Program(id, "program description here");
	}
	
	public Syllabus getSyllabus(int id) throws SQLException {
		return new Syllabus(id, 2.45, "descr", "ac2003", false);
	}
}